<%--
  Created by IntelliJ IDEA.
  User: LENOVO
  Date: 2023/9/19
  Time: 14:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>管理员注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f2f2f2;
            margin: 0;
            padding: 0;
        }

        h1 {
            text-align: center;
            color: #333;
            padding-top: 40px;
        }

        form {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 40px;
        }

        table {
            width: 400px;
            background-color: #fff;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }

        td {
            padding: 10px;
        }

        label {
            font-weight: bold;
        }

        input[type="text"],
        input[type="password"],
        select {
            width: 100%;
            padding: 5px 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        input[type="submit"],
        input[type="button"] {
            padding: 10px 20px;
            background-color: #007bff;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-top: 20px;
        }

        input[type="submit"]:hover,
        input[type="button"]:hover {
            background-color: #0056b3;
        }

        .error-msg {
            color: red;
            font-size: 14px;
            margin-top: 5px;
        }

        .success-msg {
            color: green;
            font-size: 14px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
<h1>管理员注册</h1>
<form method="post" action="AddServlet">
    <table>
        <tr>
            <td><label for="AdminName">姓名：</label></td>
            <td><input type="text" id="AdminName" name="AdminName" required></td>
        </tr>
        <tr>
            <td><label for="account">账号：</label></td>
            <td><input type="text" id="account" name="account" required></td>
        </tr>
        <tr>
            <td><label for="password">密码：</label></td>
            <td><input type="password" id="password" name="password" required></td>
        </tr>
        <tr>
            <td><label for="confirmPassword">确认密码：</label></td>
            <td><input type="password" id="confirmPassword" name="confirmPassword" required></td>
        </tr>
        <tr>
            <td><label for="telephone">电话号码：</label></td>
            <td><input type="text" id="telephone" name="telephone" required></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" name="send" value="发送短信" onclick="sendCode()"></td>
        </tr>
        <tr>
            <td>验证码：</td>
            <td>
                <input id="code" name="code">
                <span class="error-msg" id="msgCode"></span>
            </td>
        </tr>
        <tr>
            <td>邮箱：</td>
            <td><input id="to" name="to"></td>
        </tr>
        <tr>
            <td>验证码：</td>
            <td>
                <input id="picCode" name="picCode" onblur="checkPicCode()">
                <img id="pic" src="PictureCodeServlet" alt="验证码" onclick="chagePicCode()">
                <span class="error-msg" id="msgPicCode"></span>
            </td>
        </tr>
        <tr>
            <td><label for="authentication">是否认证：</label></td>
            <td>
                <select id="authentication" name="authentication">
                    <option value="1">是</option>
                    <option value="0">否</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><input type="submit" value="注册"></td>
        </tr>
    </table>
</form>
<script src="js/jquery.js"></script>
<script>
    function checkPicCode() {
        var userCode = $("#picCode").val();
        $.post("CheckPicCodeServlet", "code=" + userCode, function (data) {
            if (data === "true") {
                $("#msgPicCode").html("✔").removeClass("error-msg").addClass("success-msg");
            } else {
                $("#msgPicCode").html("✘").removeClass("success-msg").addClass("error-msg");
            }
        }, "text");
    }

    function chagePicCode() {
        $("#pic").attr("src", "PictureCodeServlet?temp=" + new Date());
    }

    function sendCode() {
        var phoneStr = $("#telephone").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/RLUtilsServlet",
            data: {"phone": phoneStr},
            success: function (data) {
                if (data === 0) {
                    alert("发送成功!");
                } else {
                    alert("发送失败!");
                }
            }
        });
    }

    $("#confirmPassword").blur(function () {
        var password = $("#password").val();
        var confirmPassword = $("#confirmPassword").val();
        if (password !== confirmPassword) {
            alert("密码不一致，请确认密码一致");
        }
    });

    $("#code").blur(function () {
        var userCode = $("#code").val();
        $.post("ChePhoneServlet", "code=" + userCode, function (data) {
            if (data === "true") {
                $("#msgCode").html("✔").removeClass("error-msg").addClass("success-msg");
            } else {
                $("#msgCode").html("✘").removeClass("success-msg").addClass("error-msg");
            }
        }, "text");
    });
</script>
</body>
</html>
